clear

suffix = 'sushi';

x = dlmread(strcat('x_' , suffix , '.csv'));
pref = dlmread(strcat('pref_' , suffix , '.csv'));
pref_test = dlmread(strcat('pref_' , suffix , '_test.csv'));

si = size(x,1);
K = zeros(si, si);
gamma = .1;
for i = 1 : si
    for j = 1 : i
        K(i,j) = gaussian_kernel(x(i,:), x(j,:), gamma);
        K(j,i) = K(i,j);
    end
end

[ mu, Sigma ] = ep(K, pref, .2);

m = inv(Sigma)*mu;

correct = 0;
itr = 1;
k_star = zeros(2, size(K, 1));

for itr = 1 : length(pref_test)
    for i = 1 : size(x, 1)
        k_star(1, i) = gaussian_kernel(x(i,:), x(pref_test(itr, 1)), gamma);
    end

    for i = 1 : size(x, 1)
        k_star(2, i) = gaussian_kernel(x(i,:), x(pref_test(itr, 2)), gamma);
    end
    
    mean = k_star * m;
    fprintf('mean: %d\n', mean);
    if(mean(1) > mean(2))
        correct = correct + 1;
    end
end



fprintf('%d out of %d', correct, length(pref_test));